package config

import (
	"imi/controller"
	"strings"
)

type Ctr = map[string]interface{}

var routers = make(map[string]Ctr)

func GetRouter(route string) (ctr Ctr) {
	index := strings.Index(route, "?")
	if index > 1 {
		route = route[0:index]
	}
	routers["/error"] = configure(new(controller.ErrorController), "Index", false)
	routers["/index"] = configure(new(controller.IndexController), "GetUser", true)
	routers["/user/register"] = configure(new(controller.UserController), "Register", true)
	routers["/user/login"] = configure(new(controller.UserController), "Login", false)
	return routers[route]
}

func configure(class interface{}, fun string, auth bool) Ctr {
	var ctr = make(Ctr)
	ctr["func"] = fun
	ctr["class"] = class
	ctr["auth"] = auth
	return ctr
}
